package com.example.gcode;

import android.app.Application;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.gcloud.dto.GCloudFile;

public class GCloudSingleton extends Application {

	private static GCloudSingleton gCloudSingleton = null;
	private List<GCloudFile> filesFromAllService;

	public GCloudSingleton() {
		filesFromAllService = new ArrayList<GCloudFile>();
	}

	public static GCloudSingleton getInstance() {
		if (GCloudSingleton.gCloudSingleton != null) {
			return GCloudSingleton.gCloudSingleton;
		}
		GCloudSingleton.gCloudSingleton = new GCloudSingleton();
		return GCloudSingleton.gCloudSingleton;
	}

	@Override
	public void onCreate() {
		filesFromAllService = new ArrayList<GCloudFile>();
		if (GCloudSingleton.gCloudSingleton == null) {
			GCloudSingleton.gCloudSingleton = new GCloudSingleton();
		}
	}

	public List<GCloudFile> getFilesFromAllService() {
		// try {
		if (filesFromAllService != null) {
			return filesFromAllService;
		}
		// Thread thead = new Thread(new Runnable() {
		// @Override
		// public void run() {
		// // TODO fill list from service
		// }
		// });
		// thead.start();
		// } catch (Exception e) {
		// // TODO IO Exception
		// }
		return filesFromAllService;
	}

	public void setFilesFromAllService(List<GCloudFile> filesFromAllService) {
		if (this.filesFromAllService != null
				&& !this.filesFromAllService.isEmpty()) {
			this.filesFromAllService.clear();
			this.filesFromAllService.addAll(filesFromAllService);
		} else {
			this.filesFromAllService = filesFromAllService;
		}
	}

}
